﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Collections;

namespace iResume
{
    public partial class recruiterCreate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SetCaptchaText();
                rightlbl.Text = (string)Session["Captcha"];

            }
            txbcName.Focus();


      

     
        }
        private void SetCaptchaText()
        {
            Random oRandom = new Random();
            int iNumber = oRandom.Next(100000, 999999);
            Session["Captcha"] = iNumber.ToString();
        }

        protected void txbcName_TextChanged(object sender, EventArgs e)
        {

        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (tbxCapcha.Text != rightlbl.Text)
            {

                Panel5.Visible = true;
            }
            else
            {
                Panel5.Visible = false;
                 // RecruiterView = DBManager.retrieveRecruiter(username);
                 ArrayList validateEmail = new ArrayList();
                 validateEmail = DBManager.retrieveREmail();

                 foreach (string mail in validateEmail)
                 {
                     if (mail == tbxEmail.Text)
                     {
                         lblError.Visible = true;
                     }

                 }
                if(lblError.Visible == false)

                {
                 string companyName = txbcName.Text;
                 string personInCharge = tbxPerson.Text;
                 string email = tbxEmail.Text;


                 string password = tbxP.Text;
                 string rePassword = tbxrP.Text;

                 string HashedPassword = "";
                 string HashedRePassword = "";



                 //Hashed Password

                 HashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(tbxP.Text, "sha1");
                 tbxP.Text = HashedPassword;


                 HashedRePassword = FormsAuthentication.HashPasswordForStoringInConfigFile(tbxrP.Text, "sha1");
                 tbxrP.Text = HashedRePassword;

                 //Hashed Password

                 txbcName.Text = "";
                 tbxPerson.Text = "";
                 tbxEmail.Text = "";
                 tbxP.Text = "";
                 tbxrP.Text = "";
                 tbxCapcha.Text = "";

                 Recruiter r = new Recruiter(companyName, personInCharge, email, HashedPassword, HashedRePassword);
                 DBManager myDBManager = new DBManager();
                 DBManager.createRecruiter(r);

                 Response.Redirect("createRecruiterAcctSuccess.aspx");
  
                     
                 
            }
          
            
              
            }

        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        bool ReturnValue()
        {
            return false;
        }
        protected void ckbTC_CheckedChanged(object sender, EventArgs e)
        {
           
                if (ckbTC.Checked == true)
                {
                    btnRegister.Enabled = true;
                    btnRegister.Focus();
             
                }
                else
                {

                    btnRegister.Enabled = false;

                }
            
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {

            
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
           
            
        }
    }
}